//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;
using OpenLS.Drawing.Serialization;

namespace OpenLS.Drawing
{
    public class NonVisualConnectorProperties : IOfficeXmlSerializable
    {
        private ConnectorLocking cxnSpLocks;
        private Connection endCxn;

        private Connection stCxn;

        public ConnectorLocking ConnectorLocking
        {
            get { return cxnSpLocks; }
            set { cxnSpLocks = value; }
        }

        public Connection StartConnection
        {
            get { return stCxn; }
            set { stCxn = value; }
        }

        public Connection EndConnection
        {
            get { return endCxn; }
            set { endCxn = value; }
        }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read("cNvCxnSpPr"))
            {
                ConnectorLocking = c.ReadOptionalElement<ConnectorLocking>("cxnSpLocks");
                StartConnection = c.ReadOptionalElementAs<Connection>("stCxn");
                EndConnection = c.ReadOptionalElementAs<Connection>("endCxn");
                c.WarnIf("ext");
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.WriteAndSwitch("cNvCxnSpPr", DrawingConstants.DrawingNamespace))
            {
                c.WriteOptionalElement(ConnectorLocking);
                c.WriteOptionalElementAs(StartConnection, "stCxn");
                c.WriteOptionalElementAs(EndConnection, "endCxn");
                c.WarnIf("ext");
            }
        }

        #endregion
    }
}